﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<div id="createDialog" class="container-fluid">
    <div class="row">
        <form id="createForm" method="post" class="form-horizontal" action="">
        <div class="form-group">
            <label class="col-sm-4 control-label" for="mchid">
                <span class="help-inline"><font color="red">*</font> </span>
                选择系统商户：</label>
            <div class="col-sm-5">
                <select id="mchid" name="mchid" class="form-control">
                    <c:forEach var="mchInfo" items="${payMchList}">
                        <option value="${mchInfo.mchid}">${mchInfo.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="channelid">
                <span class="help-inline"><font color="red">*</font> </span>
                选择第三方渠道：</label>
            <div class="col-sm-5">
                <select id="channelid" name="channelid" class="form-control">
                    <c:forEach var="upmsDict" items="${channelList}">
                        <option value="${upmsDict.dicValue}">${upmsDict.dicText}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="channelname">
                <span class="help-inline"><font color="red">*</font> </span>
                第三方渠道名称</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="channelname" name="channelname" maxlength="50" value="${payPayChannel.channelname}" placeholder="第三方渠道名称" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="channelmchid">
                <span class="help-inline"><font color="red">*</font> </span>
                第三方渠道商户appId</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="channelmchid" name="channelmchid" maxlength="50" value="${payPayChannel.channelmchid}" placeholder="第三方渠道商户appId" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="param">配置参数：</label>
            <div class="col-sm-5">
                <textarea class="form-control" id="param" name="param" placeholder="配置参数,json字符串">${payPayChannel.param}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="state">
                状态：</label>
            <div class="col-sm-5">
                <select id="state" name="state" class="form-control">
                    <option value="1" <c:if test="${payPayChannel.state==1}">selected="selected"</c:if>>启用</option>
                    <option value="0" <c:if test="${payPayChannel.state==0}">selected="selected"</c:if>>>禁止</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label" for="remark">备注：</label>
            <div class="col-sm-5">
                <textarea class="form-control" id="remark" name="remark" placeholder="备注">${payPayChannel.remark}</textarea>
            </div>
        </div>
            <div class="form-group">
        <div class="col-sm-9 col-sm-offset-4">
            <button type="button" class="btn btn-primary" onclick="createSubmit();">
                保存
            </button>
            <button type="button" class="btn btn-default"
                    onclick="createDialog.close();">取消
            </button>
        </div>
            </div>
    </form>
    </div>
</div>
<script>
function createSubmit() {
    $.ajax({dataType: 'json',
        type: 'post',
        url: '${basePath}/manage/channel/create',
        data: $('#createForm').serialize(),
        beforeSend: function() {
            if ($('#channelname').val() == '') {
                $('#channelname').focus();
                return false;
            }
            if ($('#channelmchid').val() == '') {
                $('#channelmchid').focus();
                return false;
            }
            if ($('#param').val() == '') {
                $('#param').focus();
                return false;
            }
        },
        success: function(result) {
			if (result.code != 1) {
				if (result.data instanceof Array) {
					$.each(result.data, function(index, value) {
						$.confirm({
							theme: 'dark',
							animation: 'rotateX',
							closeAnimation: 'rotateX',
							title: false,
							content: value.errorMsg,
							buttons: {
								confirm: {
									text: '确认',
									btnClass: 'waves-effect waves-button waves-light'
								}
							}
						});
					});
				} else {
						$.confirm({
							theme: 'dark',
							animation: 'rotateX',
							closeAnimation: 'rotateX',
							title: false,
							content: result.data,
							buttons: {
								confirm: {
									text: '确认',
									btnClass: 'waves-effect waves-button waves-light'
								}
							}
						});
				}
			} else {
				createDialog.close();
				$table.bootstrapTable('refresh');
			}
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
			$.confirm({
				theme: 'dark',
				animation: 'rotateX',
				closeAnimation: 'rotateX',
				title: false,
				content: textStatus,
				buttons: {
					confirm: {
						text: '确认',
						btnClass: 'waves-effect waves-button waves-light'
					}
				}
			});
        }
    });
}
</script>